<script setup>
  import { ref } from 'vue'
  import { toast } from '@/utils/utils'
  import { truckRegistration } from '@/apis/task.js'
  import slVehicleViolation from './components/vehicle-violation'
  import slVehicleBreakdown from './components/vehicle-breakdown'
  import slVehicleAccident from './components/vehicle-accident'

  // 回车时间
  const dataTimePicker = ref('')
  // 交通违章
  const jiaoTongWeiZhang = ref({})
  // 车辆故障
  const cheLiangGuZhang = ref({})
  // 交通事故
  const jiaoTongShiGu = ref({})

  //违章类型没有拿到text

  const submit = async () => {
    const formData = {
      accidentDescription: 'string', //事故说明
      accidentImagesList: 1, //事故图片列表
      accidentType: 'string', //事故类型
      breakRulesDescription: 'string', //违章说明
      breakRulesType: jiaoTongWeiZhang.value.breakRulesType, //违章类型
      deductPoints: 0, //扣分数据
      endTime: 'string', //回车时间
      faultDescription: 'string', //故障说明
      faultImagesList: 2, //故障图片列表
      faultType: 'string', //故障类型
      id: 'string', //运输任务id
      isAccident: true, //是否出现事故
      isAvailable: true, //车辆是否可用
      isBreakRules: jiaoTongWeiZhang.value.isBreakRules, //车辆是否违章
      isFault: true, //车辆是否故障
      penaltyAmount: 'string', //罚款金额
      startTime: 'string', //出车时间
    }
    console.log(formData)
    // await truckRegistration(formData)
    toast('回车登记成功')
    // setTimeout(uni.switchTab, 1500, { url: '/pages/task/index' })
  }
</script>
<template>
  <view class="page-container">
    <scroll-view class="scroll-view" scroll-y>
      <view class="scroll-view-wrapper">
        <uni-list class="base-info">
          <uni-list-item title="出车时间" show-arrow right-text="2022-05-04 13:00:00" />
          <uni-list-item show-arrow title="回车时间">
            <template v-slot:footer>
              <uni-datetime-picker v-model="dataTimePicker">
                <view class="picker-value">{{ dataTimePicker || '请选择' }}</view>
              </uni-datetime-picker>
            </template>
          </uni-list-item>
        </uni-list>
        <!-- 交通违章 -->
        <sl-vehicle-violation v-model="jiaoTongWeiZhang"></sl-vehicle-violation>
        <!-- 车辆故障 -->
        <sl-vehicle-breakdown v-model="cheLiangGuZhang"></sl-vehicle-breakdown>
        <!-- 交通事故 -->
        <sl-vehicle-accident v-model="jiaoTongShiGu"></sl-vehicle-accident>
      </view>
    </scroll-view>
    <view class="toolbar">
      <button class="button" @click="submit">提交登记</button>
    </view>
  </view>
</template>

<style lang="scss" scoped>
  @import './index.scss';
</style>
